package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {


        Person person = new Person("张三", 22);
        System.out.println(person);
        Class cls=Class.forName("reflect.Person");
        Constructor c=cls.getConstructor(String.class,int.class);
        //new Person("李四",33);

        Object obj=c.newInstance("张三",22);
        System.out.println(obj);

        Constructor c2=cls.getConstructor(String.class);
        Object obj2=c2.newInstance("李四");
        System.out.println(obj2);

    }

}
